/*
 * DesktopApplication2View.java
 */

package taikai;

import taikai.draws.DrawStrategySelectionPanel;
import taikai.draws.DrawStrategy;
import javax.swing.event.ListDataEvent;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.event.ListDataListener;

/**
 * The application's main frame.
 */
public class DesktopApplication2View extends FrameView {

    public DesktopApplication2View(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            @Override
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });


        data.getTeams().addListDataListener(new ListDataListener() {

            @Override
            public void intervalAdded(ListDataEvent lde) { }

            @Override
            public void intervalRemoved(ListDataEvent lde) { }

            @Override
            public void contentsChanged(ListDataEvent lde) {
                drawButton.setEnabled(data.getTeams().getSize()>0);
                System.out.println(data.getTeams() + " > 0 = " + data.getTeams().getSize() );
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = TaikaiApplication.getApplication().getMainFrame();
            aboutBox = new DesktopApplication2AboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        TaikaiApplication.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jSplitPane2 = new javax.swing.JSplitPane();
        controlPanel = new javax.swing.JPanel();
        teamCount = new javax.swing.JLabel();
        peopleCount = new javax.swing.JLabel();
        strategyLabel = new javax.swing.JLabel();
        teamEventCheckBox = new javax.swing.JCheckBox();
        jSplitPane3 = new javax.swing.JSplitPane();
        peopleTeamAndMatchesPane = new javax.swing.JSplitPane();
        peopleAndTeamsPane = new javax.swing.JSplitPane();
        peopleScrollPane = new javax.swing.JScrollPane();
        tableOfPeople = new javax.swing.JTable();
        jXTitledPanel1 = new org.jdesktop.swingx.JXTitledPanel();
        teamsScrollPane = new javax.swing.JScrollPane();
        listOfTeams = new javax.swing.JList();
        createTeamButton = new javax.swing.JButton();
        jSplitPane5 = new javax.swing.JSplitPane();
        tree1 = new taikai.tree.Tree();
        jPanel6 = new javax.swing.JPanel();
        matchesPane = new javax.swing.JScrollPane();
        tableOfMatches = new javax.swing.JTable();
        tableOfMatches.setDefaultRenderer(taikai.TeamOrPlayer.class, new taikai.TeamOrPlayerTableCellRenderer());
        drawButton = new javax.swing.JButton();
        jSplitPane4 = new javax.swing.JSplitPane();
        matchPanel = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jComboBox4 = new javax.swing.JComboBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jComboBox3 = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        timeLabel = new javax.swing.JLabel();
        stopWatchToggleButton = new javax.swing.JToggleButton();
        stopWatchProgress = new javax.swing.JProgressBar();
        jButton2 = new javax.swing.JButton();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        data = new taikai.Data();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        listOfTeamMembers = new javax.swing.JList();
        jScrollPane5 = new javax.swing.JScrollPane();
        listOfPeople = new javax.swing.JList();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        stopWatch = new taikai.stopwatch.StopWatch();
        personRenderer = new taikai.PersonRenderer();
        prompt = new taikai.Prompt();

        mainPanel.setName("mainPanel"); // NOI18N

        jSplitPane2.setBorder(null);
        jSplitPane2.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane2.setResizeWeight(1.0);
        jSplitPane2.setMaximumSize(new java.awt.Dimension(1000, 1000));
        jSplitPane2.setName("jSplitPane2"); // NOI18N
        jSplitPane2.setOneTouchExpandable(true);

        controlPanel.setBounds(new java.awt.Rectangle(0, 0, 100, 100));
        controlPanel.setMaximumSize(new java.awt.Dimension(100, 100));
        controlPanel.setName("controlPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(taikai.TaikaiApplication.class).getContext().getResourceMap(DesktopApplication2View.class);
        teamCount.setText(resourceMap.getString("teamCount.text")); // NOI18N
        teamCount.setName("teamCount"); // NOI18N

        peopleCount.setText(resourceMap.getString("peopleCount.text")); // NOI18N
        peopleCount.setName("peopleCount"); // NOI18N

        strategyLabel.setText(resourceMap.getString("strategyLabel.text")); // NOI18N
        strategyLabel.setName("strategyLabel"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(taikai.TaikaiApplication.class).getContext().getActionMap(DesktopApplication2View.class, this);
        teamEventCheckBox.setAction(actionMap.get("teamEventToggle")); // NOI18N
        teamEventCheckBox.setText(resourceMap.getString("teamEventCheckBox.text")); // NOI18N
        teamEventCheckBox.setName("teamEventCheckBox"); // NOI18N

        org.jdesktop.layout.GroupLayout controlPanelLayout = new org.jdesktop.layout.GroupLayout(controlPanel);
        controlPanel.setLayout(controlPanelLayout);
        controlPanelLayout.setHorizontalGroup(
            controlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(controlPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(teamEventCheckBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 138, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(controlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(controlPanelLayout.createSequentialGroup()
                        .add(150, 150, 150)
                        .add(controlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(strategyLabel)
                            .add(peopleCount)))
                    .add(teamCount))
                .addContainerGap(349, Short.MAX_VALUE))
        );
        controlPanelLayout.setVerticalGroup(
            controlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(controlPanelLayout.createSequentialGroup()
                .add(10, 10, 10)
                .add(controlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(teamEventCheckBox)
                    .add(teamCount))
                .add(6, 6, 6)
                .add(peopleCount)
                .add(22, 22, 22)
                .add(strategyLabel)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        peopleCount.setText("People: " + data.getPlayers().getRowCount());

        jSplitPane2.setBottomComponent(controlPanel);

        jSplitPane3.setBorder(null);
        jSplitPane3.setResizeWeight(0.5);
        jSplitPane3.setName("jSplitPane3"); // NOI18N
        jSplitPane3.setOneTouchExpandable(true);

        peopleTeamAndMatchesPane.setBorder(null);
        peopleTeamAndMatchesPane.setDividerLocation(200);
        peopleTeamAndMatchesPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        peopleTeamAndMatchesPane.setResizeWeight(0.5);
        peopleTeamAndMatchesPane.setName("peopleTeamAndMatchesPane"); // NOI18N
        peopleTeamAndMatchesPane.setOneTouchExpandable(true);

        peopleAndTeamsPane.setBorder(null);
        peopleAndTeamsPane.setDividerLocation(500);
        peopleAndTeamsPane.setResizeWeight(0.5);
        peopleAndTeamsPane.setName("peopleAndTeamsPane"); // NOI18N
        peopleAndTeamsPane.setOneTouchExpandable(true);

        peopleScrollPane.setName("peopleScrollPane"); // NOI18N

        tableOfPeople.setModel(data.getPlayers());
        tableOfPeople.setAutoCreateRowSorter(true);
        tableOfPeople.setName("tableOfPeople"); // NOI18N
        tableOfPeople.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        tableOfPeople.setShowGrid(false);
        tableOfPeople.setDefaultEditor(Grade.class, new taikai.GradeEditor());
        tableOfPeople.setDefaultRenderer(Grade.class, personRenderer);
        tableOfPeople.setDefaultRenderer(String.class, personRenderer);
        tableOfPeople.setDefaultRenderer(Team.class, personRenderer);
        peopleScrollPane.setViewportView(tableOfPeople);

        peopleAndTeamsPane.setLeftComponent(peopleScrollPane);

        jXTitledPanel1.setTitle(resourceMap.getString("jXTitledPanel1.title")); // NOI18N
        jXTitledPanel1.setName("jXTitledPanel1"); // NOI18N
        jXTitledPanel1.getContentContainer().setLayout(new java.awt.BorderLayout());

        teamsScrollPane.setBorder(null);
        teamsScrollPane.setName("teamsScrollPane"); // NOI18N

        listOfTeams.setModel(data.getTeams());
        listOfTeams.setName("listOfTeams"); // NOI18N
        teamsScrollPane.setViewportView(listOfTeams);

        jXTitledPanel1.getContentContainer().add(teamsScrollPane, java.awt.BorderLayout.CENTER);

        createTeamButton.setAction(actionMap.get("createTeam")); // NOI18N
        createTeamButton.setText(resourceMap.getString("createTeamButton.text")); // NOI18N
        createTeamButton.setName("createTeamButton"); // NOI18N
        jXTitledPanel1.getContentContainer().add(createTeamButton, java.awt.BorderLayout.SOUTH);

        peopleAndTeamsPane.setRightComponent(jXTitledPanel1);

        peopleTeamAndMatchesPane.setLeftComponent(peopleAndTeamsPane);

        jSplitPane5.setBorder(null);
        jSplitPane5.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane5.setResizeWeight(0.5);
        jSplitPane5.setName("jSplitPane5"); // NOI18N
        jSplitPane5.setOneTouchExpandable(true);

        tree1.setBackground(resourceMap.getColor("tree1.background")); // NOI18N
        tree1.setName("tree1"); // NOI18N
        jSplitPane5.setBottomComponent(tree1);

        jPanel6.setName("jPanel6"); // NOI18N
        jPanel6.setLayout(new java.awt.BorderLayout());

        matchesPane.setBorder(null);
        matchesPane.setName("matchesPane"); // NOI18N

        tableOfMatches.setModel(data.getMatches());
        tableOfMatches.setName("tableOfMatches"); // NOI18N
        matchesPane.setViewportView(tableOfMatches);

        jPanel6.add(matchesPane, java.awt.BorderLayout.CENTER);

        drawButton.setAction(actionMap.get("draw")); // NOI18N
        drawButton.setText(resourceMap.getString("drawButton.text")); // NOI18N
        drawButton.setName("drawButton"); // NOI18N
        jPanel6.add(drawButton, java.awt.BorderLayout.SOUTH);

        jSplitPane5.setTopComponent(jPanel6);

        peopleTeamAndMatchesPane.setRightComponent(jSplitPane5);

        jSplitPane3.setLeftComponent(peopleTeamAndMatchesPane);

        jSplitPane4.setBorder(null);
        jSplitPane4.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane4.setResizeWeight(0.5);
        jSplitPane4.setName("jSplitPane4"); // NOI18N
        jSplitPane4.setOneTouchExpandable(true);

        matchPanel.setMaximumSize(new java.awt.Dimension(400, 400));
        matchPanel.setName("matchPanel"); // NOI18N
        matchPanel.setLayout(new javax.swing.BoxLayout(matchPanel, javax.swing.BoxLayout.LINE_AXIS));

        jPanel3.setBackground(resourceMap.getColor("jPanel3.background")); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox1.setName("jComboBox1"); // NOI18N

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox2.setName("jComboBox2"); // NOI18N

        jCheckBox1.setText(resourceMap.getString("jCheckBox1.text")); // NOI18N
        jCheckBox1.setName("jCheckBox1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .add(12, 12, 12)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jCheckBox1)
                    .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1)
                    .add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(141, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jCheckBox1)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        matchPanel.add(jPanel3);

        jPanel4.setBackground(resourceMap.getColor("jPanel4.background")); // NOI18N
        jPanel4.setName("jPanel4"); // NOI18N

        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox4.setName("jComboBox4"); // NOI18N

        jCheckBox2.setText(resourceMap.getString("jCheckBox2.text")); // NOI18N
        jCheckBox2.setName("jCheckBox2"); // NOI18N

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox3.setName("jComboBox3"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jComboBox3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2)
                    .add(jComboBox4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jCheckBox2))
                .addContainerGap(58, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jComboBox3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jComboBox4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jCheckBox2)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        matchPanel.add(jPanel4);

        jSplitPane4.setTopComponent(matchPanel);

        jPanel5.setName("jPanel5"); // NOI18N

        timeLabel.setBackground(resourceMap.getColor("timeLabel.background")); // NOI18N
        timeLabel.setFont(timeLabel.getFont().deriveFont(timeLabel.getFont().getStyle() | java.awt.Font.BOLD, 36));
        timeLabel.setForeground(resourceMap.getColor("timeLabel.foreground")); // NOI18N
        timeLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        timeLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        timeLabel.setName("timeLabel"); // NOI18N
        timeLabel.setOpaque(true);

        stopWatchToggleButton.setAction(actionMap.get("stopWatch")); // NOI18N
        stopWatchToggleButton.setText(resourceMap.getString("stopWatchToggleButton.text")); // NOI18N
        stopWatchToggleButton.setName("stopWatchToggleButton"); // NOI18N

        stopWatchProgress.setBackground(resourceMap.getColor("stopWatchProgress.background")); // NOI18N
        stopWatchProgress.setForeground(resourceMap.getColor("stopWatchProgress.foreground")); // NOI18N
        stopWatchProgress.setName("stopWatchProgress"); // NOI18N

        jButton2.setAction(actionMap.get("resetTime")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, timeLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE)
                    .add(stopWatchProgress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE)
                    .add(jPanel5Layout.createSequentialGroup()
                        .add(stopWatchToggleButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton2)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(stopWatchProgress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(timeLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
                .add(18, 18, 18)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(stopWatchToggleButton)
                    .add(jButton2))
                .addContainerGap())
        );

        jSplitPane4.setRightComponent(jPanel5);

        jSplitPane3.setRightComponent(jSplitPane4);

        jSplitPane2.setLeftComponent(jSplitPane3);

        org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jSplitPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 779, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jSplitPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE)
        );

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        org.jdesktop.layout.GroupLayout statusPanelLayout = new org.jdesktop.layout.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 779, Short.MAX_VALUE)
            .add(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(statusMessageLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 523, Short.MAX_VALUE)
                .add(progressBar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(statusPanelLayout.createSequentialGroup()
                .add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(statusMessageLabel)
                    .add(statusAnimationLabel)
                    .add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(3, 3, 3))
        );

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jSplitPane1.setDividerLocation(100);
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane1.setName("jSplitPane1"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        listOfTeamMembers.setName("listOfTeamMembers"); // NOI18N
        jScrollPane4.setViewportView(listOfTeamMembers);

        jScrollPane5.setName("jScrollPane5"); // NOI18N

        listOfPeople.setName("listOfPeople"); // NOI18N
        jScrollPane5.setViewportView(listOfPeople);

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
                .add(18, 18, 18)
                .add(jScrollPane5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 152, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane4, 0, 0, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE))
                .addContainerGap())
        );

        jSplitPane1.setRightComponent(jPanel1);

        jPanel2.setName("jPanel2"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(325, Short.MAX_VALUE)
                .add(jButton1)
                .add(52, 52, 52))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(43, 43, 43)
                .add(jButton1)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jSplitPane1.setTopComponent(jPanel2);

        jTabbedPane1.addTab(resourceMap.getString("jSplitPane1.TabConstraints.tabTitle"), jSplitPane1); // NOI18N

        stopWatch.setLabel(timeLabel);
        stopWatch.setProgressBar(progressBar);
        stopWatch.setToggleButton(stopWatchToggleButton);

        personRenderer.setText(resourceMap.getString("personRenderer.text")); // NOI18N
        personRenderer.setName("personRenderer"); // NOI18N
        personRenderer.setPeople(data.getPlayers() );

        setComponent(mainPanel);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void createTeam() {
        final String teamName = prompt.teamName(getFrame(), listOfTeams.getModel().getSize());
        if(teamName!=null) {
            data.createTeam(tableOfPeople.getSelectedRows(), teamName);
            teamCount.setText("Teams: " + listOfTeams.getModel().getSize());
        }
    }

    @Action
    public void draw() {
        DrawStrategySelectionPanel generate = new DrawStrategySelectionPanel(this.getFrame(), data.getTeamsOrPlayers()){
            @Override
            public void onClose(DrawStrategy strategy) {
                data.generateMatches(strategy, teamEventCheckBox.isSelected());
                strategyLabel.setText(strategy.getName());
            }
        };
        generate.setVisible(true);
    }

    @Action
    public void teamEventToggle() {
        setTeamEvent(teamEventCheckBox.isSelected());
        data.getPlayers().setTeamEvent(teamEventCheckBox.isSelected());
    }

    public void setTeamEvent(boolean teamEvent) {
        createTeamButton.setEnabled(teamEvent);

        if(teamEvent)  {
            peopleTeamAndMatchesPane.remove(peopleScrollPane);
            peopleTeamAndMatchesPane.setTopComponent(peopleAndTeamsPane);
            peopleAndTeamsPane.setLeftComponent(peopleScrollPane);
        }else {
            peopleAndTeamsPane.remove(peopleScrollPane);
            peopleTeamAndMatchesPane.remove(peopleAndTeamsPane);
            peopleTeamAndMatchesPane.setLeftComponent(peopleScrollPane);
        }

    }

    @Action
    public void stopWatch() {
        stopWatch.press();
        setStopWatchText(false);
    }

    private void setStopWatchText(boolean reset) {
        if (stopWatchToggleButton.isSelected()) {
            stopWatchToggleButton.setText("Pause");
        } else {
            stopWatchToggleButton.setText("Start");
            if(!reset)stoppage.setVisible(true);
        }
    }

    @Action
    public void resetTime() {
        stopWatch.reset();
        stopWatchToggleButton.setSelected(false);
        setStopWatchText(true);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    javax.swing.JPanel controlPanel;
    javax.swing.JButton createTeamButton;
    taikai.Data data;
    javax.swing.JButton drawButton;
    javax.swing.JButton jButton1;
    javax.swing.JButton jButton2;
    javax.swing.JCheckBox jCheckBox1;
    javax.swing.JCheckBox jCheckBox2;
    javax.swing.JComboBox jComboBox1;
    javax.swing.JComboBox jComboBox2;
    javax.swing.JComboBox jComboBox3;
    javax.swing.JComboBox jComboBox4;
    javax.swing.JLabel jLabel1;
    javax.swing.JLabel jLabel2;
    javax.swing.JPanel jPanel1;
    javax.swing.JPanel jPanel2;
    javax.swing.JPanel jPanel3;
    javax.swing.JPanel jPanel4;
    javax.swing.JPanel jPanel5;
    javax.swing.JPanel jPanel6;
    javax.swing.JScrollPane jScrollPane4;
    javax.swing.JScrollPane jScrollPane5;
    javax.swing.JSplitPane jSplitPane1;
    javax.swing.JSplitPane jSplitPane2;
    javax.swing.JSplitPane jSplitPane3;
    javax.swing.JSplitPane jSplitPane4;
    javax.swing.JSplitPane jSplitPane5;
    javax.swing.JTabbedPane jTabbedPane1;
    org.jdesktop.swingx.JXTitledPanel jXTitledPanel1;
    javax.swing.JList listOfPeople;
    javax.swing.JList listOfTeamMembers;
    javax.swing.JList listOfTeams;
    javax.swing.JPanel mainPanel;
    javax.swing.JPanel matchPanel;
    javax.swing.JScrollPane matchesPane;
    javax.swing.JSplitPane peopleAndTeamsPane;
    javax.swing.JLabel peopleCount;
    javax.swing.JScrollPane peopleScrollPane;
    javax.swing.JSplitPane peopleTeamAndMatchesPane;
    taikai.PersonRenderer personRenderer;
    private javax.swing.JProgressBar progressBar;
    taikai.Prompt prompt;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    javax.swing.JPanel statusPanel;
    taikai.stopwatch.StopWatch stopWatch;
    javax.swing.JProgressBar stopWatchProgress;
    javax.swing.JToggleButton stopWatchToggleButton;
    javax.swing.JLabel strategyLabel;
    javax.swing.JTable tableOfMatches;
    javax.swing.JTable tableOfPeople;
    javax.swing.JLabel teamCount;
    javax.swing.JCheckBox teamEventCheckBox;
    javax.swing.JScrollPane teamsScrollPane;
    javax.swing.JLabel timeLabel;
    taikai.tree.Tree tree1;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
    private Stoppage stoppage = new Stoppage(getFrame());

}
